<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>
<script>
export default {
  name: "waters",
  data() {
    return {};
  },
  created() {
    this.getBaseUserInfo();
  },
  methods: {
    getBaseUserInfo() {
      let openid = localStorage.getItem('YF_USER_INFOS_OPENID');
      if (openid) {
        this.$http
          .post(this.$API.GET_APP_USERINFO)
          .then((res) => {
            if (res.code == 1) {
              if (res.data && res.data.openid) {
                this.setStorageUser(res.data);
              } else {
                localStorage.removeItem('YF_USER_INFOS');
                localStorage.removeItem('YF_USER_INFOS_ID');
                localStorage.removeItem('YF_USER_INFOS_OPENID');
              }
            }
          });
      } else {
        localStorage.removeItem('YF_USER_INFOS');
        localStorage.removeItem('YF_USER_INFOS_ID');
        localStorage.removeItem('YF_USER_INFOS_OPENID');
      }
    },
    setStorageUser(data) {
      console.log('data', data);
      localStorage.setItem('YF_USER_INFOS', JSON.stringify(data));
      localStorage.setItem('YF_USER_INFOS_ID', data.id);
      localStorage.setItem('YF_USER_INFOS_OPENID', data.openid);
    },
  }
};
</script>